package 双指针;


/**
 * https://leetcode.cn/problems/palindrome-number/description/
 */
public class _9_回文数 {

    public static void main(String[] args) {
        int a = 121;
        _9_回文数 _9_回文数 = new _9_回文数();
        boolean result = _9_回文数.isPalindrome(a);
        System.out.println(result);
    }

    public boolean isPalindrome(int x) {
        if(x < 0) return false;
        int y = x;
        int result = 0;

        while (x != 0) {
            int a = x % 10;

            if (result > Integer.MAX_VALUE || result > Integer.MAX_VALUE /10) {
                return false;
            }

            if(result < Integer.MIN_VALUE || result < Integer.MIN_VALUE /10) {
                return false;
            }

            result = result * 10 + a;
            x = x/10;
        }

        return result == y;
    }

}
